<?php

namespace App\Http\Controllers;

use App\Exceptions\CoopException;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redis;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;


    public function userId( )
    {
        $redis_key = 'userInfo_'.request()->token;


        if(!$userId = Redis::get($redis_key)) {
            throw new CoopException("用户未登录");
        }
        return $userId;


    }

    public function success($data=null)
    {
        return response()->json([
            "code" => 200,
            "msg" => "请求成功",
            "data" => $data
        ]);
    }

    public function error($msg,$code="-1")
    {
        return response()->json([
            "code" => $code,
            "msg" => $msg
        ]);
    }
}
